package com.cuixichang.minimalism.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.text.MessageFormat;

@Service
public class ICacheCommandServiceImpl implements ICacheCommandService{
    @Autowired
    private CacheManager cacheManager;
    @Override
    public String getKey(String systemCode, String principal,String keyword) {
        return MessageFormat.format("{0}.{1}.{2}",systemCode,principal,keyword);
    }

    @Override
    @CachePut(value = "captcha", key = "#key")
    public String putCache(String key, String value) {
        return value;
    }

    @Override
    @Cacheable(value = "captcha", key = "#key")
    public String getValue(String key) {
        Cache captcha = cacheManager.getCache("captcha");
        return captcha.get(key, String.class);
    }
}
